<?php

/**
 * Class AuthsController
 */
class AuthsController extends AppController {

	/**
	 * Initialization
	 */
	public function beforeFilter() {
		parent::beforeFilter();
		$this->Auth->allow('create');
	}

	public function index() {
		$this->autoLayout = $this->autoRender = false;
		$template = <<<HTML
			<h1>This is `index()` function</h1>
HTML;
		die($template);
	}

	public function test() {
		$this->autoLayout = $this->autoRender = false;
		$template = <<<HTML
			<h1>This is `test()` function</h1>
HTML;
		die($template);
	}

	/**
	 * Create user and role data
	 */
	public function create() {
		exit('Already done');
		$this->autoLayout = $this->autoRender = false;

		/**
		 * Add role
		 */
		$Role = ClassRegistry::init('Role');
		$Role->create();
		$Role->save([
			'id' => 1,
			'name' => 'Administrator',
			'description' => 'administrator description',
		]);
		$Role->create();
		$Role->save([
			'id' => 2,
			'name' => 'Manager',
			'description' => 'manager description',
		]);
		$Role->create();
		$Role->save([
			'id' => 3,
			'name' => 'User',
			'description' => 'user description',
		]);
		$Role->create();
		$Role->save([
			'id' => 4,
			'name' => 'Visitor',
			'description' => 'visitor description',
		]);

		/**
		 * Add user
		 */
		$User = ClassRegistry::init('User');
		$User->create();
		$User->save([
			'id' => 1,
			'email' => 'boss@qq.com',
			'password' => 'boss123',
			'is_active' => 1,
			'role_id' => 1,
		]);
		$User->create();
		$User->save([
			'id' => 2,
			'email' => 'cto@qq.com',
			'password' => 'cto123',
			'is_active' => 1,
			'role_id' => 2,
		]);
		$User->create();
		$User->save([
			'id' => 3,
			'email' => 'developer@qq.com',
			'password' => 'developer123',
			'is_active' => 1,
			'role_id' => 2,
		]);
		$User->create();
		$User->save([
			'id' => 4,
			'email' => 'tester@qq.com',
			'password' => 'tester123',
			'is_active' => 1,
			'role_id' => 3,
		]);
		$User->create();
		$User->save([
			'id' => 5,
			'email' => 'xiaohe@qq.com',
			'password' => 'xiaohe123',
			'is_active' => 1,
			'role_id' => 4,
		]);
		die('Completed');
	}
}
